package com.rightsidetech.http.controller.admin.mall;

import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.github.pagehelper.PageInfo;
import com.rightsidetech.mall.dto.request.BrandPageReq;
import com.rightsidetech.mall.dto.request.BrandReq;
import com.rightsidetech.mall.dto.request.BrandUpdateReq;
import com.rightsidetech.mall.dto.response.BrandListResp;
import com.rightsidetech.mall.dto.response.BrandPageResp;
import com.rightsidetech.mall.service.MallBrandService;
import com.rightsidetech.commom.base.DelReq;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.system.service.SysUserLoginInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/mall_brand/")
@ShenyuSpringMvcClient(path = "/admin/mall_brand/**")
@Api(tags = "Admin:商品品牌相关")
public class MallBrandController extends BaseController {

    @Resource
    private MallBrandService mallBrandService;
    @Resource
    private SysUserLoginInfoService sysUserLoginInfoService;

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/save")
    @ApiOperation("添加商品品牌")
    public ResponseData saveBrand(@RequestBody BrandReq req) throws Exception{
        Long loginInfoId = Long.parseLong(getAttribute());
        String loginName = getLoginName();
        if(null == loginInfoId || null == loginName){
            return ResponseData.fail("未找到登录人");
        }
        return mallBrandService.save(req, loginName,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/update")
    @ApiOperation("更新商品品牌")
    public ResponseData updateName(@RequestBody BrandUpdateReq request) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        String loginName = getLoginName();
        if(null == loginInfoId || null == loginName){
            return ResponseData.fail("未找到登录人");
        }
        return mallBrandService.updateBrand(request,loginName,loginInfoId);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/del")
    @ApiOperation("删除商品品牌")
    public ResponseData delBrand(@RequestBody DelReq req){
        return mallBrandService.isDelete(req);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/page_brand")
    @ApiOperation("分页查询商品品牌")
    public ResponseData<PageInfo<BrandPageResp>> pageBrand(BrandPageReq req){
        return mallBrandService.pageBrand(req);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/search")
    @ApiOperation("品牌下拉选")
    public ResponseData<List<BrandListResp>> selectList(@RequestParam(value = "brandName",required = false) String brandName){
         return mallBrandService.selectList(brandName);
    }
}
